﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using com.nm.ApiServer;
using com.nm.ApiServer.Attributes;
using com.nm.Attributes;
using com.nm.db.Models.Terminal;
using Senparc.Weixin.Helpers.Extensions;
using Senparc.Weixin.Work.AdvancedAPIs;
using Senparc.Weixin.Work.AdvancedAPIs.MailList;
using Senparc.Weixin.Work.Containers;
using Senparc.Weixin.Work.Helpers;
using WeiXinAPI.Common;

namespace WeiXinAPI
{
    public class WxAutoSendSettingHandler : BaseHandler
    {
        #region GetWxAutoSendSettingList

        [MustLogin]
        [Description("获取企业关系列表")]
        [ReturnType(typeof(IList<AutoSend_Setting>))]
        public ApiResult GetWxAutoSendSettingList()
        {
            var dc = new TerminalEntities();
            var list = dc.AutoSend_Setting.Include(setting => setting.AutoSend_MsgTemplate).ToList();
            return Success(list);
        }

        #endregion

        #region 获取 GetWxAutoSendSetting

        [MustLogin]
        [Description("获取")]
        [ReturnType(typeof(int))]
        public ApiResult GetWxAutoSendSetting(int Id)
        {
            if (Id <= 0)
            {
                return Error("参数异常，请重新再试");
            }

            var dc = new TerminalEntities();
            var model = dc.AutoSend_Setting.FirstOrDefault(x => x.Id == Id);
            if (model != null)
            {
                return Success(model);
            }
            return Error("找不到对应的信息，请重新再试");
        }

        #endregion


        #region 删除设置 RemoveWxAutoSendSetting

        [MustLogin]
        [Description("删除设置")]
        [ReturnType(typeof(int))]
        public ApiResult RemoveWxAutoSendSetting(int Id)
        {
            if (Id <= 0)
            {
                return Error("参数异常，请重新再试");
            }

            var dc = new TerminalEntities();
            var model = dc.AutoSend_Setting.FirstOrDefault(x => x.Id == Id);
            if (model != null)
            {
                dc.AutoSend_Setting.Remove(model);
                var result = dc.SaveChanges();
                return Success(result);
            }
            return Error("删除失败！找不到对应的信息");
        }

        #endregion

    }




}
